import 'package:XinXiZiXun/common/utils/utils.dart';
import 'package:XinXiZiXun/common/values/values.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

///是否同意协议
class ZdyAgreement extends StatefulWidget {
  @required
  final String selectedImageString;
  @required
  final String unSelectedImageString;
  @required
  final String prevNameString;
  @required
  final String nextNameString;
  bool isSelectedBool;
  ValueSetter<bool> callBackRespone;

  ZdyAgreement(
      {Key key,
      this.selectedImageString,
      this.unSelectedImageString,
      this.prevNameString,
      this.nextNameString,
      this.isSelectedBool = false,
      this.callBackRespone})
      : super(key: key);

  @override
  _ZdyAgreementState createState() => _ZdyAgreementState();
}

class _ZdyAgreementState extends State<ZdyAgreement> {
  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        InkWell(
          child: Image.asset(
            (widget.isSelectedBool
                ? widget.selectedImageString
                : widget.unSelectedImageString),
            width: duSetHeight(ktDefaultPadding),
            height: duSetHeight(ktDefaultPadding),
            fit: BoxFit.fill,
          ),
          onTap: () {
            widget.isSelectedBool = !widget.isSelectedBool;

            widget.callBackRespone(widget.isSelectedBool);

            setState(() {});
          },
        ),
        SizedBox(
          width: duSetWidth(kDefaultPadding),
        ),
        RichText(
          text: TextSpan(
            text: '我已阅读并同意',
            style: TextStyle(
              color: AppColors.primaryDarkGrayColor,
              fontSize: duSetScaleFontSize(20),
            ),
            children: [
              TextSpan(
                text: widget.prevNameString,
                style: TextStyle(
                  color: AppColors.primaryElementColor,
                  fontSize: duSetScaleFontSize(20),
                ),
                recognizer: TapGestureRecognizer()
                  ..onTap = () {
                    print('点击使用条款');
                  },
              ),
              TextSpan(
                text: '和',
                style: TextStyle(
                  color: AppColors.primaryDarkGrayColor,
                  fontSize: duSetScaleFontSize(20),
                ),
              ),
              TextSpan(
                text: widget.nextNameString,
                style: TextStyle(
                  color: AppColors.primaryElementColor,
                  fontSize: duSetScaleFontSize(20),
                ),
                recognizer: TapGestureRecognizer()
                  ..onTap = () {
                    print('点击隐私政策');
                  },
              ),
            ],
          ),
        ),
      ],
    );
  }
}
